package com.zhiyou100.service.imp;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.zhiyou100.IService.QuestionService;
import com.zhiyou100.entity.TbQuestion;
import com.zhiyou100.entity.TbQuestionExample;
import com.zhiyou100.entity.TbQuestionExample.Criteria;
import com.zhiyou100.mapper.TbQuestionMapper;

@Service("qusetionServiceimp")
public class QusetionServiceImp implements QuestionService{
	@Resource(name="tbQuestionMapper")
	private TbQuestionMapper tbQuestionMapper;
	

	public List<TbQuestion> queryQuestionOne() {
		TbQuestionExample tbo= new TbQuestionExample();
		Criteria criteria = tbo.createCriteria();
		criteria.andQuestionIdEqualTo(1);
		List<TbQuestion> tbQuestions = tbQuestionMapper.selectByExample(tbo);
		String a = tbQuestions.get(0).getQuestionTitle();
		TbQuestionExample tbo1= new TbQuestionExample();
		Criteria criteria1 = tbo1.createCriteria();
		criteria1.andQuestionTitleIdEqualTo(1);
		List<TbQuestion> tb = tbQuestionMapper.selectByExample(tbo1);
		for(TbQuestion tbQuestion : tb) {
			tbQuestion.setQuestionTitle(a);
		}
		return tb;
	}

	public List<TbQuestion> queryQuestionTwo() {
		TbQuestionExample tbo= new TbQuestionExample();
		Criteria criteria = tbo.createCriteria();
		criteria.andQuestionIdEqualTo(2);
		List<TbQuestion> tbQuestions = tbQuestionMapper.selectByExample(tbo);
		String a = tbQuestions.get(0).getQuestionTitle();
		TbQuestionExample tbo1= new TbQuestionExample();
		Criteria criteria1 = tbo1.createCriteria();
		criteria1.andQuestionTitleIdEqualTo(2);
		List<TbQuestion> tb = tbQuestionMapper.selectByExample(tbo1);
		for(TbQuestion tbQuestion : tb) {
			tbQuestion.setQuestionTitle(a);
		}
		return tb;
	}

	public List<TbQuestion> queryQuestionThr() {
		TbQuestionExample tbo= new TbQuestionExample();
		Criteria criteria = tbo.createCriteria();
		criteria.andQuestionIdEqualTo(3);
		List<TbQuestion> tbQuestions = tbQuestionMapper.selectByExample(tbo);
		String a = tbQuestions.get(0).getQuestionTitle();
		TbQuestionExample tbo1= new TbQuestionExample();
		Criteria criteria1 = tbo1.createCriteria();
		criteria1.andQuestionTitleIdEqualTo(3);
		List<TbQuestion> tb = tbQuestionMapper.selectByExample(tbo1);
		for(TbQuestion tbQuestion : tb) {
			tbQuestion.setQuestionTitle(a);
		}
		return tb;
	}

	public List<TbQuestion> queryQuestionFor() {
		TbQuestionExample tbo= new TbQuestionExample();
		Criteria criteria = tbo.createCriteria();
		criteria.andQuestionIdEqualTo(4);
		List<TbQuestion> tbQuestions = tbQuestionMapper.selectByExample(tbo);
		String a = tbQuestions.get(0).getQuestionTitle();
		TbQuestionExample tbo1= new TbQuestionExample();
		Criteria criteria1 = tbo1.createCriteria();
		criteria1.andQuestionTitleIdEqualTo(4);
		List<TbQuestion> tb = tbQuestionMapper.selectByExample(tbo1);
		for(TbQuestion tbQuestion : tb) {
			tbQuestion.setQuestionTitle(a);
		}
		return tb;
		
	}

	public void updateq(Integer id,String title,String name,String answer) {
		TbQuestionExample tbo= new TbQuestionExample();
		Criteria criteria = tbo.createCriteria();
		criteria.andQuestionIdEqualTo(id);
		tbQuestionMapper.selectByExample(tbo).get(0).setQuestionName(name);
		tbQuestionMapper.selectByExample(tbo).get(0).setQuestionAnswer(answer);
		tbQuestionMapper.selectByExample(tbo).get(0).setQuestionTitle(title);
		tbQuestionMapper.updateByPrimaryKey(tbQuestionMapper.selectByExample(tbo).get(0));
	}

	
}
